package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IShopRecordService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.ShopRecordCreateValidate;
import com.mdd.admin.validate.ShopRecordUpdateValidate;
import com.mdd.admin.validate.ShopRecordSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ShopRecordListedVo;
import com.mdd.admin.vo.ShopRecordDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.ShopRecord;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/record")
@Api(tags = "开店申请管理")
public class ShopRecordController {

    @Resource
    IShopRecordService iShopRecordService;

    @GetMapping("/list")
    @ApiOperation(value="开店申请列表")
    public AjaxResult<PageResult<ShopRecordListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated ShopRecordSearchValidate searchValidate) {
        PageResult<ShopRecordListedVo> list = iShopRecordService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="开店申请详情")
    public AjaxResult<ShopRecordDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ShopRecordDetailVo detail = iShopRecordService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "开店申请新增")
    @PostMapping("/add")
    @ApiOperation(value="开店申请新增")
    public AjaxResult<Object> add(@Validated @RequestBody ShopRecordCreateValidate createValidate) {
        iShopRecordService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "开店申请编辑")
    @PostMapping("/edit")
    @ApiOperation(value="开店申请编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ShopRecordUpdateValidate updateValidate) {
        iShopRecordService.edit(updateValidate);
        return AjaxResult.success();
    }
    
    @Log(title = "开店申请编辑")
    @PostMapping("/examine")
    @ApiOperation(value="开店申请审核")
    public AjaxResult<Object> examine(@Validated @RequestBody ShopRecord record) {
        iShopRecordService.examine(record);
        return AjaxResult.success();
    }

    @Log(title = "开店申请删除")
    @PostMapping("/del")
    @ApiOperation(value="开店申请删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iShopRecordService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
